<?php

namespace app\storeapi\model\resources;
use app\common\model\resources\Resources as ResourcesModel;


/**
 * 资源模型
 * Class User
 * @package app\store\model
 */
class Resources extends ResourcesModel
{

    /**
     * 获取课件列表
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function getList($param)
    {
        $page = isset($param['page']) && is_numeric($param['page']) ? intval($param['page']) : 1;
        $limit = 15;
        $offset = ($page - 1) * $limit;
        return $this->useGlobalScope(false)
            ->field('resources_id,resources_title')
            ->where('is_delete', '=', 0)
            ->order(['resources_sort' => 'asc', 'create_time' => 'desc'])
            ->limit($offset, $limit)
            ->select();

    }





    /**
     * 获取课件详情
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function info($param)
    {
        $resources_id = $param['resources_id'];
        //增加浏览量
        $this->useGlobalScope(false)->where(['resources_id'=>$resources_id])->setInc('actual_views');

        return $this->useGlobalScope(false)
            ->alias('a')
            ->join('yoshop_upload_file b','a.down_id=b.file_id')
            ->where(['a.resources_id'=>$resources_id])
            ->find();

    }

    /**
     * 获取课件下载
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function down($param)
    {
        $resources_id = $param['resources_id'];
        //增加浏览量
        $this->useGlobalScope(false)->where(['resources_id'=>$resources_id])->setInc('down_times');

    }




}
